<template>
	<view>
		<view class="user">
			<text v-text="user.className"></text>
			<text v-text="user.name"></text>
		</view>
		<pickerModule :picker="item" v-for="(item,index) in picker" :key="index" @pickerChange="pickerChange"></pickerModule>
		<view class="noRecord" v-if="noRecord">
			<image src="../../static/noRecord.png"></image>
			<text>无教评记录!</text>
		</view>
		<baseForm v-else :column.sync="column" :button="button"></baseForm>
	</view>
</template>

<script>
	import baseForm from "@/wxcomponents/form/form.vue";
	import pickerModule from "@/wxcomponents/form/picker.vue";
	import common from "@/libs/login.js"
	import qs from 'qs'
	import {
		format,
		dictCode
	} from "@/libs/common.js"
	export default {
		data() {
			let that = this;
			return {
				user: "",
				picker: [{
						label: "日期",
						value: format("YY-mm-dd", new Date()),
						required: true,
						name: "datePicker",
						mode: "date",
						text: format("YY-mm-dd", new Date())
					},
					{
						label: "课程",
						value: "",
						required: true,
						mode: "selector",
						name: "courseName",
						range: "",
						text: "请选择课程"
					},
					{
						label: "教师",
						value: "",
						required: true,
						name: "teacherName",
						mode: "selector",
						disabled:true,
						range: "",
						text: "请选择教师"
					}
				],
				column: [],
				teacherClass: "",
				button: {
					hide: true
				},
				noRecord: false

			}
		},
		async onLoad() {
			this.teacherClass = await this.getTeacherClass()
			this.picker[1].range = await this.setFormList(this.teacherClass, 'courseName', 'courseCode')
			this.picker[2].range = await this.setFormList(this.teacherClass, 'teacherName', 'jobNumber')
			this.user = await common.getStorage('user')
		},
		methods: {
			async checkReport() {
				let that = this
				let list = await this.$http.post({
					url: "/edu/questionAnswer/listByStudent",
					data: {
						courseCode: this.picker[1].value,
						jobNumber: this.picker[2].value,
						submitDate: this.picker[0].value,
						studentNumber: ""
					}
				})
				if (list.result.length !== 0) {
					let answerSaveVoStr = JSON.parse(list.result[0].answerSaveVoStr)
					that.column = answerSaveVoStr.map(item => {
						if (item.questionType == 1) {
							return {
								label: `${item.name}`,
								name: item.name,
								type: 'normalInput',
								disabled: true,
								value:  item.answerDesc,
								showIndex: true,
								configId: item.id,
								sortNum: item.sortNum,
								questionType: item.questionType,
								// answerOptionType: '',
								// answerDesc: '',
							};
						} else {
						return {
							label: item.name,
							name: item.name,
							type: "radio",
							disabled: true,
							value: item.answerOptionType,
							// id: item.id,
							configId: item.configId,
							sortNum: item.sortNum,
							questionType: item.questionType,
							answerOptionType: item.answerOptionType,
							answerDesc: "",
							// questionType:dictCode('dict_questionnaire_type', item.questionType),
							answerAType: item.answerAType,
							answerBType: item.answerBType,
							showIndex:true,
							items: [{
									value: item.answerAType ,
									name: item.answerAType == 1 ? '是' : '否'
								},
								{
									value: item.answerBType ,
									name: item.answerBType == 1 ? '是' : '否'
								}
							]
						}
						}
					})
					that.submitDisable = true
					this.noRecord = false
				} else {
					this.noRecord = true
				}
			},
			async getTeacherClass(name, id) {
				let that = this
				let resp = await this.$http.post({
					url: "/edu/questionAnswer/listCourseByStudentAndDate",
					data: {
						submitDate: that.picker[0].value
					}
				})
				return resp.result
			},
			async setFormList(teacherClass, name, id) {
				let arr = ""
				return arr = teacherClass.map(item => {
					return {
						name: item[name],
						id: item[id]
					}
				})
			},
			async pickerChange(e) {
				let findOne = this.picker.filter(item => {
					return item.name == e.name
				})[0]
				if (findOne) {
					findOne.text = e.text;
					findOne.value = e.value;
					if(findOne.mode =='selector'){
						let arr = e.range.map(item=>item.id)
						let index = arr.indexOf(e.value)
						this.picker[2].value = this.picker[2].range[index].id
						this.picker[2].text = this.picker[2].range[index].name
					}
				}
				this.teacherClass = await this.getTeacherClass()
				this.picker[1].range = await this.setFormList(this.teacherClass, 'courseName', 'courseCode')
				this.picker[2].range = await this.setFormList(this.teacherClass, 'teacherName', 'jobNumber')
				this.checkReport()
			},
		},
		components: {
			baseForm,
			pickerModule
		},

		computed: {

		},

	}
</script>

<style lang="scss" scoped>
	.user {
		text {
			font-size: 36upx;
			font-family: Source Han Sans CN;
			font-weight: bold;
			color: rgba(51, 51, 51, 1);
			margin-right: 20upx;
			display: inline-block;
		}

		padding: 50upx;
	}

	.noRecord {
		image {
			width: 421upx;
			height: 217upx;
			display: block;
			margin: 20upx auto;
		}

		text {
			font-size: 32upx;
			text-align: center;
			width: 100%;
			display: inline-block;
			margin: 20upx 0;
			font-family: Source Han Sans CN;
			font-weight: 400;
			color: rgba(51, 51, 51, 1);
		}
	}
</style>
